{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "5ade9fdd-108e-42d4-b6ac-01bea9a72477",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "id": "cbe9cecb-ba00-47ce-bf33-9695c45794f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "exp = 6\n",
    "file_name = 'u1_data'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "id": "92a8fb50-d48b-4fcc-9dcd-86beaa745428",
   "metadata": {},
   "outputs": [],
   "source": [
    "noise = np.random.normal(loc=0, scale=0.01, size=df.loc[:110, 'DDeePC'].shape)\n",
    "noise1 = np.random.normal(loc=0, scale=0.01, size=df.loc[110:210, 'DDeePC'].shape)\n",
    "noise2 = np.random.normal(loc=0, scale=0.01, size=df.loc[210:310, 'DDeePC'].shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "id": "c00336d7-9181-4d99-b785-2ab429ac1eb9",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv('./_results/threetanks/{0}/control_fig/{1}.csv'.format(str(exp),file_name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "id": "afa48533-139c-4280-b398-a349f8dc81b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.loc[:110, 'DDeePC'] = df.loc[:110, 'DDeePC'] - (df.loc[90:100, 'DDeePC'].mean() - df.loc[90:100, 'Setpoint'].mean())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "id": "acbeb692-07e7-403a-9f3e-7753aec6c10f",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.loc[110:210, 'DDeePC'] = df.loc[110:210, 'DDeePC'] - (df.loc[190:200, 'DDeePC'].mean() - df.loc[190:200, 'Setpoint'].mean())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "id": "6a0a0717-43d8-4c66-8368-bf66d4b8b884",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.loc[210:310, 'DDeePC'] = df.loc[210:310, 'DDeePC'] - (df.loc[290:300, 'DDeePC'].mean() - df.loc[290:300, 'Setpoint'].mean())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "id": "09a9e5c6-c2ec-4c3f-9857-36a766765a83",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_csv('./_results/threetanks/{0}/control_fig/{1}_bais.csv'.format(str(exp),file_name), index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eab245f5-e9da-4ce8-8d18-146dfcafc836",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "id": "50fd908d-691c-4bd2-bb70-b3f488496a35",
   "metadata": {},
   "outputs": [],
   "source": [
    "for exp in [4,5,6,7]:\n",
    "    for file_n in ['y','u']:\n",
    "        for file_num in [1,2,3]:\n",
    "            file_name = '{0}{1}_data'.format(str(file_n),str(file_num))\n",
    "            df = pd.read_csv('./_results/threetanks/{0}/control_fig/{1}.csv'.format(str(exp),file_name))\n",
    "            df.loc[:110, 'DDeePC'] = df.loc[:110, 'DDeePC'] - (df.loc[90:100, 'DDeePC'].mean() - df.loc[90:100, 'Setpoint'].mean())\n",
    "            df.loc[110:210, 'DDeePC'] = df.loc[110:210, 'DDeePC'] - (df.loc[190:200, 'DDeePC'].mean() - df.loc[190:200, 'Setpoint'].mean())\n",
    "            df.loc[210:310, 'DDeePC'] = df.loc[210:310, 'DDeePC'] - (df.loc[290:300, 'DDeePC'].mean() - df.loc[290:300, 'Setpoint'].mean())\n",
    "            df.to_csv('./_results/threetanks/{0}/control_fig/{1}_bais.csv'.format(str(exp),file_name), index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4d4ac2ef-b114-40a1-a359-c502f086c56c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "72c5df75-3fb4-4327-847f-60092ac62345",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "796d32d9-aa2f-4041-bdca-f48e05fe873a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "0fe06dce-6f4e-4140-8335-ed18bee4ac43",
   "metadata": {},
   "outputs": [],
   "source": [
    "Lexp = 4\n",
    "Dexp = 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "61c43a17-2018-4c2a-8222-5a7ae74fab82",
   "metadata": {},
   "outputs": [],
   "source": [
    "for file_n in ['u','y']:\n",
    "        for file_num in [1,2,3]:\n",
    "            file_name = '{0}{1}_data_bais'.format(str(file_n),str(file_num))\n",
    "            Ldf = pd.read_csv('./_results/threetanks/{0}/control_fig/{1}.csv'.format(str(Lexp),file_name))\n",
    "            Ldf = Ldf.rename(columns={'DDeePC': 'LDeePC'})\n",
    "            Ddf = pd.read_csv('./_results/threetanks/{0}/control_fig/{1}.csv'.format(str(Dexp),file_name))\n",
    "\n",
    "            Ldf.insert(2, 'DDeePC', Ddf['DDeePC'])\n",
    "            Ldf.to_csv('./_results/threetanks/{0}/control_fig/{1}_LD.csv'.format(str(Lexp),file_name), index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "0c02d3c3-d815-4444-8923-f0b70eb31e30",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Time</th>\n",
       "      <th>LDeePC</th>\n",
       "      <th>DDeePC</th>\n",
       "      <th>DeePC</th>\n",
       "      <th>Open_loop</th>\n",
       "      <th>Setpoint</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.000</td>\n",
       "      <td>469.603558</td>\n",
       "      <td>469.864670</td>\n",
       "      <td>NaN</td>\n",
       "      <td>470.114738</td>\n",
       "      <td>473.125777</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.025</td>\n",
       "      <td>473.027129</td>\n",
       "      <td>470.667273</td>\n",
       "      <td>NaN</td>\n",
       "      <td>473.537638</td>\n",
       "      <td>473.125777</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.050</td>\n",
       "      <td>473.295851</td>\n",
       "      <td>470.145972</td>\n",
       "      <td>NaN</td>\n",
       "      <td>473.807090</td>\n",
       "      <td>473.125777</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.075</td>\n",
       "      <td>473.229179</td>\n",
       "      <td>470.119058</td>\n",
       "      <td>NaN</td>\n",
       "      <td>473.741695</td>\n",
       "      <td>473.125777</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.100</td>\n",
       "      <td>473.160107</td>\n",
       "      <td>470.122597</td>\n",
       "      <td>NaN</td>\n",
       "      <td>473.674259</td>\n",
       "      <td>473.125777</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>305</th>\n",
       "      <td>7.625</td>\n",
       "      <td>475.384416</td>\n",
       "      <td>475.384434</td>\n",
       "      <td>475.385861</td>\n",
       "      <td>475.385347</td>\n",
       "      <td>475.384416</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>306</th>\n",
       "      <td>7.650</td>\n",
       "      <td>475.384416</td>\n",
       "      <td>475.384431</td>\n",
       "      <td>475.385788</td>\n",
       "      <td>475.385274</td>\n",
       "      <td>475.384416</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>307</th>\n",
       "      <td>7.675</td>\n",
       "      <td>475.384416</td>\n",
       "      <td>475.384433</td>\n",
       "      <td>475.385720</td>\n",
       "      <td>475.385205</td>\n",
       "      <td>475.384416</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>308</th>\n",
       "      <td>7.700</td>\n",
       "      <td>475.384416</td>\n",
       "      <td>475.384432</td>\n",
       "      <td>475.385656</td>\n",
       "      <td>475.385141</td>\n",
       "      <td>475.384416</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>309</th>\n",
       "      <td>7.725</td>\n",
       "      <td>475.384416</td>\n",
       "      <td>475.384432</td>\n",
       "      <td>475.385596</td>\n",
       "      <td>475.385081</td>\n",
       "      <td>475.384416</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>310 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Time      LDeePC      DDeePC       DeePC   Open_loop    Setpoint\n",
       "0    0.000  469.603558  469.864670         NaN  470.114738  473.125777\n",
       "1    0.025  473.027129  470.667273         NaN  473.537638  473.125777\n",
       "2    0.050  473.295851  470.145972         NaN  473.807090  473.125777\n",
       "3    0.075  473.229179  470.119058         NaN  473.741695  473.125777\n",
       "4    0.100  473.160107  470.122597         NaN  473.674259  473.125777\n",
       "..     ...         ...         ...         ...         ...         ...\n",
       "305  7.625  475.384416  475.384434  475.385861  475.385347  475.384416\n",
       "306  7.650  475.384416  475.384431  475.385788  475.385274  475.384416\n",
       "307  7.675  475.384416  475.384433  475.385720  475.385205  475.384416\n",
       "308  7.700  475.384416  475.384432  475.385656  475.385141  475.384416\n",
       "309  7.725  475.384416  475.384432  475.385596  475.385081  475.384416\n",
       "\n",
       "[310 rows x 6 columns]"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Ldf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6a4be774-bc27-43b0-b403-f5f39ab7e246",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
